#ifndef KEYBOARD_LAYOUT
#define KEYBOARD_LAYOUT

#include <touchgfx/widgets/Keyboard.hpp>
#include <touchgfx/hal/Types.hpp>
#include <fonts/ApplicationFontProvider.hpp>
#include "BitmapDatabase.hpp"

using namespace touchgfx;
#ifndef SIMULATOR
static const int KEY_WIDTH = 60;
static const int KEY_HEIGHT = 60;

static const int KEY_ROW_1_Y = 170;
static const int KEY_ROW_2_Y = 240;
static const int KEY_ROW_3_Y = 310;
static const int KEY_ROW_4_Y = 380;

static const int KEY_ROW_1_X = 19;
static const int KEY_ROW_1_X_KEY_DISTANCE = 70;

static const int KEY_ROW_2_X = 19;
static const int KEY_ROW_2_X_KEY_DISTANCE = 70;

static const int KEY_ROW_3_X = 159;
static const int KEY_ROW_3_X_KEY_DISTANCE = 70;

static const int SPACE_WIDTH = 480;
static const int SPACE_X = 159;

static const int SPECIAL_BUTTONS_WIDTH = 130;

static const int CAPS_LOCK_X = 19;
static const int MODE_X = 19;
static const int BACKSPACE_X = 649;
static const int DONE_X = 649;

/**
 * Array specifying the keys used in the CustomKeyboard.
 */
static const Keyboard::Key keyArray[30] =
{
    { 1, Rect(KEY_ROW_1_X,                                  KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 2, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE,       KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 3, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 2,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 4, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 3,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 5, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 4,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 6, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 5,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 7, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 6,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 8, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 7,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    { 9, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 8,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {10, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 9,   KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {11, Rect(KEY_ROW_1_X + KEY_ROW_1_X_KEY_DISTANCE * 10,  KEY_ROW_1_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},

    {12, Rect(KEY_ROW_2_X,                                  KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {13, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE,       KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {14, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 2,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {15, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 3,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {16, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 4,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {17, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 5,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {18, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 6,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {19, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 7,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {20, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 8,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {21, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 9,   KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {22, Rect(KEY_ROW_2_X + KEY_ROW_2_X_KEY_DISTANCE * 10,  KEY_ROW_2_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},

    {23, Rect(KEY_ROW_3_X,                                  KEY_ROW_3_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {24, Rect(KEY_ROW_3_X + KEY_ROW_3_X_KEY_DISTANCE,       KEY_ROW_3_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {25, Rect(KEY_ROW_3_X + KEY_ROW_3_X_KEY_DISTANCE * 2,   KEY_ROW_3_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {26, Rect(KEY_ROW_3_X + KEY_ROW_3_X_KEY_DISTANCE * 3,   KEY_ROW_3_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {27, Rect(KEY_ROW_3_X + KEY_ROW_3_X_KEY_DISTANCE * 4,   KEY_ROW_3_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {28, Rect(KEY_ROW_3_X + KEY_ROW_3_X_KEY_DISTANCE * 5,   KEY_ROW_3_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},
    {29, Rect(KEY_ROW_3_X + KEY_ROW_3_X_KEY_DISTANCE * 6,   KEY_ROW_3_Y, KEY_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_KEY_ID},

    {30, Rect(SPACE_X, KEY_ROW_4_Y, SPACE_WIDTH, KEY_HEIGHT), BITMAP_KEYBOARD_PRESSED_SPACE_ID}
};

/**
 * Callback areas for the special buttons on the CustomKeyboard.
 */
static Keyboard::CallbackArea callbackAreas[6] =
{
    {Rect(CAPS_LOCK_X,  KEY_ROW_3_Y, SPECIAL_BUTTONS_WIDTH, KEY_HEIGHT), 0, BITMAP_KEYBOARD_PRESSED_CAPSLOCK_ID},    // caps-lock
    {Rect(BACKSPACE_X,  KEY_ROW_3_Y, SPECIAL_BUTTONS_WIDTH, KEY_HEIGHT), 0, BITMAP_KEYBOARD_PRESSED_BACKSPACE_ID},   // backspace    
    {Rect(MODE_X,       KEY_ROW_4_Y, SPECIAL_BUTTONS_WIDTH, KEY_HEIGHT), 0, BITMAP_KEYBOARD_PRESSED_MODE_ID},        // mode
    {Rect(DONE_X,       KEY_ROW_4_Y, SPECIAL_BUTTONS_WIDTH, KEY_HEIGHT), 0, BITMAP_KEYBOARD_PRESSED_DONE_ID}         // done
};

/**
 * The layout for the CustomKeyboard.
 */
static const Keyboard::Layout layout =
{
    BITMAP_KEYBOARD_NORMAL_ID,
    keyArray,
    30,
    callbackAreas,
    4,
    Rect(5, 75, 790, 90),
    TypedText(T_ENTEREDTEXT),
#if !defined(USE_BPP) || USE_BPP==16
    0xe6fc,
#elif USE_BPP==24
    0xEBEBEB,
#elif USE_BPP==4
    0xF,
#elif USE_BPP==2
    0x3,
#else
#error Unknown USE_BPP
#endif
    Typography::KEYBOARD,
#if !defined(USE_BPP) || USE_BPP==16
    0xFFFF,
#elif USE_BPP==24
    0xFFFFFF,
#endif
};
#endif //SIMULATOR

#endif
